<template>
  <el-form-item prop="productLimit" label="兑换限制（件/人）" :rules="rules">
    <el-input v-model="modelValue"></el-input>
  </el-form-item>
</template>

<script lang="ts" setup>
const props = withDefaults(defineProps<{
  modelValue: number
}>(), {
  modelValue: 0
})
const emits = defineEmits(['update:model-value'])
const modelValue = computed({
  get() {
    return props.modelValue
  },
  set(newValue) {
    emits('update:model-value', newValue)
  }
})

const rules = [
  {
    required: true,
    message: '请输入兑换限制',
    trigger: 'blur'
  },
  {
    message: '兑换限制只能是正整数',
    validator(rule: any, val: any, callback: any) {
      if (!/^[1-9]*[1-9][0-9]*$/.test(val)) {
        callback(new Error('兑换限制只能是正整数'))
      } else {
        callback()
      }
    }
  },
  {
    message: '超过上限【9999,9999】',
    validator(rule: any, val: any, callback: any) {
      if (Number(val) > 99999999) {
        callback(new Error('超过上限【9999,9999】'))
      } else {
        callback()
      }
    }
  }]
</script>

<style scoped lang="scss">

</style>
